<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="ipt">
    <script>
        let obj = {};
        
        let value = '';

        let ipt = document.querySelector('#ipt');

        Object.defineProperty(obj,'name',{
            set(newVal){
                console.log("设置值");
                value = newVal;
                ipt.value = value;
            },
            get(){
                console.log("获取值");
                return value
            }
        })

        ipt.addEventListener('input',(e) => {
            value = e.target.value
        })
    </script>
</body>
</html>